package com.zhida.smartcontrol.pagectrl.lampmanager;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.common.bean.LampBean;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 14:47
 * description:
 */
public class LampManagerPresenter extends BasePresenterImpl<LampManagerContract.View> implements LampManagerContract.Presenter {

    @Override
    public void requestList(String id, boolean showLoading) {
        Params params = Params.newBuilder()
                .add("pid", id)
                .build();
        mKalleCenter.get(Api.LAMP_SWITCH_LIST_BY_PARENT, params, showLoading, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                LampBean bean = JSON.parseObject(result, LampBean.class);

                List<LampSwitchBean> beanList = new ArrayList<>();
                beanList.addAll(bean.getNbChildSwitchList());
                beanList.addAll(bean.getZigBeeChildSwitchList());
                beanList.addAll(bean.getPlcChildSwitchList());

                mView.showSingleList(beanList);

                mView.showDoubleList(bean.getNbDbChildSwitchList());

            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
